module DataUpdateTest where
import DataUpdate
import UpdateParser
import DataParser
import Test.HUnit


twoEntryDict = (Dict $ emptyDict \\ (Int 1, Prim $ String "a") \\ (Int 2, Prim $ String "b"))

dataUpdateTests = [
    "Null Dict Equality" ~: emptyDict ~=?  emptyDict \\ (String "a", Prim Null),
    "Insert Twice" ~: emptyDict \\ (Int 1, Prim $ String "a") ~=? emptyDict \\ (Int 1, Prim $ String "b") \\ (Int 1, Prim $ String "a"),
    "find update from equal dictionaries" ~: Void ~=? findUpdate (Dict $ emptyDict \\ (Int 1, Prim $ String "a")) (Dict $ emptyDict \\ (Int 1, Prim $ String "a")), 
    "apply unchanged DUpdate" ~: twoEntryDict ~=? apply (DUpdate $ emptyDUpdate \\ (Int 2, PUpdate $ String "b")) twoEntryDict,   
    "compatible with empty dict" ~: True ~=? compatible (DUpdate emptyDUpdate) (DUpdate $ emptyDUpdate \\ (String "x", PUpdate $ String "x")),
    "effective update" ~: (DUpdate $ emptyDUpdate \\ (String "a", PUpdate $ Int 1)) ~=?  effective (DUpdate $ emptyDUpdate \\ (String "a", PUpdate $ Int 1)) (Dict emptyDict),
    "parser test" ~:  Right (Dict $ emptyDict \\ (Int 1705, Prim $ String "a1") \\ (String "bbb", Prim $ String "a1")) ~=? parseString2Value "{1705->a1,        bbb    ->           a1}",
    "parser test" ~:  Right (Prim Null) ~=? parseString2Value "null",
    "parser test" ~:  Right Void ~=? parseString2Update "void",
    "parser test" ~:  Right (Dict $ emptyDict ) ~=? parseString2Value "{}",
    "parser test" ~:  Right (DUpdate $ emptyDUpdate ) ~=? parseString2Update "{}"
    ]